<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>dal生成</title>
    <script type="text/javascript" src="/res/js/jquery-2.2.0.min.js"></script>
    <script type="text/javascript" src="/res/js/jquery.tmpl.js"></script>
  </head>
  <body>
    <select id="id_dbname" name="dbname">
      <<<str2html .Website>>>
    </select>    
    <input type="button" id="id_gettables" value="获取" />
    <label id="id_msg"></label>
    <select id="id_tabs"></select>
    <input type="button" id="id_getcloums" value="获取" />
    <table>
      <thead>
        <tr>
          <th>名称</th>
          <th>类型</th>
        </tr>
      </thead>
      <tbody id="id_table"></tbody>
     <table>
    <input id="id_btngencode" type="button" value="gencode"/>
    <pre><code id="id_gencode">

	</code></pre>
    <script id="id_tmpltables" type="text/x-jquery-tmpl">     
      <option>${$data}</option>      
    </script>
  <script id="id_tmplcols" type="text/x-jquery-tmpl">     
      <tr><td>${$data.Name}</td><td>${$data.DbType}</td></tr>      
    </script>

  <script type="text/javascript">

    $("#id_dbname").on("change",function(){
      var val = $(this).find("option:selected").val();
      $("#id_msg").html(val);
	  
    });

    $("#id_gettables").on("click",function(){
      var val = $("#id_dbname").find("option:selected").val();
      $.post("/api/gettables", {"db":val},function(data){
        console.log(data);
        $("#id_tabs").html("");
        $("#id_tmpltables").tmpl(data).appendTo("#id_tabs");
      });
    });

    $("#id_getcloums").on("click",function(){
      var db = $("#id_dbname").find("option:selected").val();
      var tab = $("#id_tabs").find("option:selected").val();
      $.post("/api/getcolumns", {"db":db,"tab":tab},function(data){
        console.log(data);
        $("#id_table").html("");
        $("#id_tmplcols").tmpl(data).appendTo("#id_table");
      });
    });
    $("#id_btngencode").on("click",function(){
		$.post("/api/codegen",function(data){
			$("#id_gencode").text(data.code);
		})
    });
   </script>
  </body>
</html>
